#include "funduspreprocessing.h"
using namespace std;
using namespace pip;

int main(int argc, char *argv[]){
  string program = argv[0];
  vector<string> args(argv, argv+argc);
  if (argc<2) error(program, "\nUsage: funduspreprocessing filename -color c -medianwidth m\n"
		    "Performs color fundus image preprocessing,\n selecting color channel c "
		    "('R','G' or 'B')\n and using a median of width m.\n");

  //get filename, color and medianwidth from command line
  string filename = argv[1];
  char color = 'R';
  getScalarArg(args, "-color", color);
  if(color != 'R' &&
     color != 'G' &&
     color != 'B'){
    error(program, "Not a valid color channel; use 'R', 'G', or 'B'\n");
    return 1;
  }
  int medianwidth = 1;
  getScalarArg(args, "-medianwidth", medianwidth);
  if(medianwidth<0){
    error(program, "Not a valid median width; use an integer>0\n");
    return 1;
  }

  Image<Color<unsigned char> > imIn;
  Image<float> imOut;
  if (!importFile(imIn,filename))
    error(program, "Error reading input file (must be 2D RGB pip image)\n");

  PreProcessFundus<float> ppf;
  ppf.setColorChannel(color);
  ppf.setMedianWidth(medianwidth);
  ppf.run(imIn,imOut);

  // save the result image
  exportFile(imOut,"fundus_prepro.pip");

  return 0;
}
